#ifndef SOUND_HH_
#   define SOUND_HH_

#	include "common/stl.h"
#   include "tools/Vector.hh"


class Sound
{
public:
  Sound(std::string fileName);

  Sound(std::string fileName, bool loop);

  ~Sound();

  /// loads a RIFF WAVE file
  bool init();

  ALint getStatus();

  // client side
  void setListenerPosition(Coords v);
  void setListenerVelocity(Coords v);
  void setListenerOrientation(Coords v);

  // server side
  void setSourcePosition(Coords v);
  void setSourceVelocity(Coords v);
  void setSourceOrientation(Coords v);

  /// _loop setter
  void setLoop(bool loop);

  void pause();
  void stop();
  void play();


private:
  void checkFileFormat();

  /** Figure out which format is it
   ** bases on \param nbBitsPerSample and \param nbChannels
   */
  ALenum getFormat(short nbBitsPerSample, short nbChannels);

  void fillData();

  void initSource();
  void initListener();

  std::string _fileName;
  bool _loop;
  FILE *_fp;
  ALuint _dataBuffer; // sound data
  ALuint _sampleRate;
  unsigned char* _buf;
  unsigned int _dataSize;

  // Source
  ALuint _source; // sound source id
  ALfloat _sourcePos[3]; // listener position
  ALfloat _sourceVel[3]; // listener velocity
  ALfloat _sourceOri[6]; // listener orientation // 6 : up axe

  // Listener
  ALfloat _listenerPos[3]; // listener position
  ALfloat _listenerVel[3]; // listener velocity
  ALfloat _listenerOri[6]; // listener orientation // 6 : up axe
};

#endif /* !SOUND_HH_ */
